package cn.jingzhuan.fm.mvp.presenter

import cn.jingzhuan.fm.mvp.contract.FMIndexContract
import cn.jingzhuan.fm.mvp.model.FMIndexModel
import io.reactivex.android.schedulers.AndroidSchedulers
import javax.inject.Inject

class FMIndexPresenter @Inject constructor(
        private val fmIndexView:FMIndexContract.View,
        private val fmIndexModel: FMIndexModel):FMIndexContract.Presenter {

    override fun getAlbumRecommendList() {
        fmIndexModel.getAlbumRecommendList().observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    if (it.isSuccess) {
                        fmIndexView.showAlbumRecommendList(it.response)
                    }
                }) {
                    fmIndexView.showAlbumRecommendList(mutableListOf())
                }
    }

    override fun getTodayListenList() {
        fmIndexModel.getTodayListenList().observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    if (it.isSuccess) {
                        fmIndexView.showTodayListenList(it.response)
                    }
                }) {
                    fmIndexView.showTodayListenList(mutableListOf())
                }
    }

    override fun getBannerList() {
        fmIndexModel.getBannerList().observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    if (it.isSuccess) {
                        fmIndexView.showBannerList(it.response)
                    }
                }) {
                    fmIndexView.showBannerList(mutableListOf())
                }
    }
}